package org.tigr.htc.cmd;

/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

import org.apache.log4j.Logger;

/**
 * The <b>ParamType</b> class follows the type safe enum pattern to define 
 * different param types.
 *
 */

public class ParamType {
    static Logger log = Logger.getLogger("org.tigr.htc.cmd.ParamType");
    
    /**
     * <code>name</code> holds the name of the type
     */
    private final String name;
    
    /**
     * Creates a new <code>ParamType</code> instance.
     *
     * @param name a <code>String</code> value
     */
    private ParamType(String p_name) {
        this.name = p_name;
    }
    
    /**
     * <code>toString</code> overridden from Object to print name.
     *
     * @return a <code>String</code> value
     */
    public String toString() {
        return name;
    }
    
    /**
     * <code>getType</code> takes a type as a string and returns the
     * correct ParamType object. Needed for object marshalling.
     *
     * @param p_type a <code>String</code> value
     * @return a <code>ParamType</code> value
     */
    public static ParamType getType(String p_type) {
        String type = p_type.toUpperCase();
        if(type.equals("PARAM")) {
            return ParamType.PARAM;
        } else if(type.equals("ANON")) {
            return ParamType.PARAM;
        } else if(type.equals("FILE")) {
            return ParamType.FILE;
        } else if(type.equals("DIR")) {
            return ParamType.DIR;
        } else if(type.equals("TEMPFILE")) {
            return ParamType.TEMPFILE;
        } else if(type.equals("ARRAY")) {
            return ParamType.ARRAY;
        } else if (type.equals("FASTAFILE")) {
            return ParamType.FASTAFILE;
        }
        log.fatal("getType got an UNKNOWN Parameter type: " + p_type);
        return ParamType.UNKNOWN;
    }
    
    // valid param types
    public static final ParamType PARAM = new ParamType("PARAM");
    public static final ParamType FILE = new ParamType("FILE");
    public static final ParamType DIR = new ParamType("DIR");
    public static final ParamType TEMPFILE = new ParamType("TEMPFILE");
    public static final ParamType ARRAY = new ParamType("ARRAY");
    public static final ParamType FASTAFILE = new ParamType("FASTAFILE");
    public static final ParamType UNKNOWN = new ParamType("UNKNOWN");
    
}
